package com.cf.base.http.core;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yangji
 */
public class RetrofitManager {


    private Map<String, RetrofitService> beanMap;
    private static RetrofitManager INSTANCE = null;

    private RetrofitManager() {
        beanMap = new HashMap<>();
    }

    public static RetrofitManager getInstance() {
        if (INSTANCE == null) {
            synchronized (RetrofitManager.class) {
                if (INSTANCE == null) {
                    INSTANCE = new RetrofitManager();
                }
            }
        }
        return INSTANCE;
    }

    /**
     * 添加全局 Retrofit
     *
     * @param moduleKey 模块名称
     * @param retrofit  请求对象
     */
    void addRetrofitBean(String moduleKey, RetrofitService retrofit) {
        this.beanMap.put(moduleKey, retrofit);
    }

    public RetrofitService getRetrofit(String moduleKey) {
        return RetrofitManager.getInstance().beanMap.get(moduleKey);
    }

    public void clear() {
        beanMap.clear();
    }

    public void clear(String moduleName) {
        beanMap.remove(moduleName);
    }
}
